package com.zm.mybatis.damai.mapper;

import com.zm.mybatis.damai.bean.Product;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface ProductMapper {
    @Select("select * from dm_product where pname like concat('%',#{ name },'%')")
    @Results(id = "rm1",
        value = {
//            <!--        设置主键字段-->
//            <id column="id" property="id" ></id>
//            <!--       手动映射，表的字段名与实体类属性名不相同需要设置-->
//            <result column="market_price" property="marketPrice"></result>
//            <result column="shop_price" property="shopPrice"></result>
//            <result column="is_hot" property="isHot"></result>
                @Result(column = "id",property = "id",id = true),
                @Result(column = "market_price",property = "marketPrice"),
                @Result(column = "shop_price",property = "shopPrice"),
                @Result(column = "is_hot",property = "isHot")
        }
    )
    List<Product> selectByName(String name);

    @Select("select * from dm_product where pdesc like concat('%',#{ desc },'%')")
    @ResultMap("rm1")
    List<Product> selectByDesc(String desc);

    @Select("select * from dm_product where id = #{id}")
    Product selectById(int id);
}
